package com.itheima.myvolatile;

public class Volatile {
    public static void main(String[] args) {
        Husband h = new Husband();
        Wife w = new Wife();
        h.setName("丈夫");
        w.setName("妻子");
        h.start();
        w.start();
    }
}
class Money{
    //加入volatile关键字, 可以强制线程每次在使用的时候，都会看一下共享区域最新的值
    public static volatile int money = 100000;
}
class Wife extends Thread{
    @Override
    public void run() {
        while(Money.money == 100000){

        }
        System.out.println("结婚基金已经不是十万了");
    }
}
class Husband extends Thread{
    @Override
    public void run() {
        try {
            Thread.sleep(10);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        Money.money = 90000;
    }
}